<?php
/*******************************************************************************
 * $Date:: Jan 10, 2011 10:20:08 PM                                             
 * $Revision:                                                                  $
 * $Author:: Tuan Duong                                                        $
 * $Comment::                                                                  $
 ******************************************************************************/ 
/**
 * Description here...
 * 
 * @package Lua
 * @subpackage Service
 * @author Tuan Duong <bacduong[at]gmail[dot]com>
 * @version 
 */

class Lua_Service_Base implements Lua_Service_Interface
{
    /**
     * @var Lua_Table_Base
     */
    private $baseTable;

    public function __construct()
    {
        $this->baseTable = new Lua_Table_Base();
    }
    /**
     * Get row from table with condition and bind result to bean
     * @param string $tableName
     * @param array|string|Zend_Db_Select_Abstract $where
     * @return Lua_Bean_Abstract
     */
    public function findRow($tableName, $where = null)
    {
        return $this->baseTable->findRow($tableName, $where);
    }

    /**
     * @param  string|array|Zend_Db_Select_Abstract $where
     * @param  string $tableName
     * @param  string|array $order
     * @param  int $count
     * @param  int $offset
     * @return array
     */
    public function findAll($tableName, $where = null, $order = null, $count = null, $offset = null)
    {
        return $this->baseTable->findAll($tableName, $where, $order, $count, $offset);
    }

    /**
     * @param  array|Lua_Bean_Abstract $data
     * @param  string $tableName
     * @return int
     */
    public function insert($tableName, $data)
    {
        return $this->baseTable->insert($tableName, $data);
    }

    /**
     * @param  array|Lua_Bean_Abstract $data
     * @param  array|string|Zend_Db_Select_Abstract $where
     * @param  string $tableName
     * @return int
     */
    public function update($tableName, $data, $where = null)
    {
        return $this->baseTable->update($tableName, $data, $where);
    }

    /**
     * @param  Lua_Bean_Abstract $bean
     * @return int
     */
    public function save(Lua_Bean_Abstract $bean)
    {
        return $this->baseTable->save($bean);
    }

    /**
     * @param string $tableName
     * @param  array|string $where
     * @return int
     */
    public function delete($tableName = '', $where = null)
    {
        return $this->baseTable->delete($tableName, $where);    
    }

    /**
     * @param  array $groupIds
     * @return array
     */
    public function getAcls(array $groupIds = null)
    {
        return $this->findAll('ipoo_acl', array('group_id IN (?)' => $groupIds));
    }
}